package cn.exempale.mscapplication.emnus;

/**
 * 音频文字转写状态
 */
public enum ProgressType {
    // 成功
    TASK(0, "任务创建完成"),
    UPLOAD(1, "音频上传完成"),
    MARGE(2, "音频合成完成"),
    TRANSFER(3, "音频转写中"),
    TRANSFER_PROGRESS(4, "转写结果处理中"),
    TRANSFER_DONE(5, "转写完成"),
    TRANSFER_UPLOAD(9, "转写结果上传完成"),
    // 失败
    TASK_FAILED(-0, "任务创建失败"),
    UPLOAD_FAILED(-1, "音频上传失败"),
    MARGE_FAILED(-2, "音频合并失败"),
    TRANSFER_FAILED(-3, "音频转写失败"),
    TRANSFER_PROGRESS_FAILED(-4, "转写结果处理失败"),
    TRANSFER_DONE_FAILED(-5, "转写失败"),
    TRANSFER_UPLOAD_FAILED(-9, "转写结果上传失败"),

    ;

    private int code;
    private String value;

    ProgressType(int code, String value) {
        this.code = code;
        this.value = value;
    }

    public int getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public static ProgressType match(int code) {
        for (ProgressType type : values())
            if (type.code == code)
                return type;
        return UPLOAD;
    }

    public static ProgressType match(String value) {
        for (ProgressType type : values())
            if (type.value.equals(value))
                return type;
        return UPLOAD;
    }

    public static ProgressType getFailedType(ProgressType progressType) {
        for (ProgressType type : values())
            if ((-type.code) == progressType.code)
                return type;
        return TASK_FAILED;
    }

    public static ProgressType getFailedType(String value) {
        ProgressType progressType = TASK;
        for (ProgressType type : values())
            if (type.value.equals(value)) {
                progressType = type;
                break;
            }
        return getFailedType(progressType);
    }

    public static ProgressType getFailedType(int code) {
        ProgressType progressType = TASK;
        for (ProgressType type : values())
            if (type.code == code) {
                progressType = type;
                break;
            }
        return getFailedType(progressType);
    }
}
